package com.jxdinfo.hussar.example.scada.tunnel.messcadatunnelkilnrecord.service.impl;

import com.jxdinfo.hussar.support.mp.base.service.impl.HussarServiceImpl;
import com.jxdinfo.hussar.support.datasource.annotations.HussarDs;
import com.jxdinfo.hussar.platform.core.utils.HussarUtils;
import com.jxdinfo.hussar.support.exception.HussarException;
import com.jxdinfo.hussar.example.scada.tunnel.messcadatunnelkilnrecord.model.MesScadaTunnelkilnRecord;
import com.jxdinfo.hussar.example.scada.tunnel.messcadatunnelkilnrecord.service.MesScadaTunnelkilnRecordService;
import com.jxdinfo.hussar.example.scada.tunnel.messcadatunnelkilnrecord.dao.MesScadaTunnelkilnRecordMapper;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
import com.jxdinfo.hussar.example.scada.tunnel.messcadatunnelkilnrecord.dto.MesScadaTunnelkilnRecordMesscadatunnelkilnrecorddataset1;
import com.jxdinfo.hussar.example.scada.tunnel.messcadatunnelkilnrecord.vo.MesScadaTunnelkilnRecordPageVO;
import com.jxdinfo.hussar.support.transaction.core.annotation.HussarTransactional;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.fastjson.JSONObject;
import com.jxdinfo.hussar.platform.core.base.apiresult.ApiResponse;

/**
 * 隧道窑记录表服务实现类
 */
@Service("scada.tunnel.messcadatunnelkilnrecord.MesScadaTunnelkilnRecordServiceImpl")
@HussarDs("master")
public class MesScadaTunnelkilnRecordServiceImpl extends HussarServiceImpl<MesScadaTunnelkilnRecordMapper, MesScadaTunnelkilnRecord> implements MesScadaTunnelkilnRecordService {

    private static final Logger logger = LoggerFactory.getLogger(MesScadaTunnelkilnRecordServiceImpl.class);

    private static final String RETURN_CODE = "0";

    @Autowired
    private MesScadaTunnelkilnRecordMapper mesScadaTunnelkilnRecordMapper;

    @Override
    public ApiResponse<MesScadaTunnelkilnRecordPageVO> hussarQueryPage(Page<MesScadaTunnelkilnRecord> page) {
        try {
            Page<MesScadaTunnelkilnRecord> pager = new Page<>(page.getCurrent(), page.getSize());
            MesScadaTunnelkilnRecordPageVO mesScadaTunnelkilnRecordPageVO = new MesScadaTunnelkilnRecordPageVO();
            List<MesScadaTunnelkilnRecord> list = this.page(pager).getRecords();
            mesScadaTunnelkilnRecordPageVO.setData(list);
            mesScadaTunnelkilnRecordPageVO.setCount(pager.getTotal());
            mesScadaTunnelkilnRecordPageVO.setCode(RETURN_CODE);
            return ApiResponse.success(mesScadaTunnelkilnRecordPageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询失败");
        }
    }

    @Override
    @HussarTransactional
    public ApiResponse<Boolean> tableSave(JSONObject tableData) {
        try {
            return ApiResponse.success(this.saveOrUpdateBatch(JSONObject.parseArray(tableData.getString("importList"), MesScadaTunnelkilnRecord.class)));
        } catch (Exception e) {
            throw new HussarException("表格保存失败");
        }
    }

    @Override
    @HussarTransactional
    public ApiResponse<Boolean> flagDelete(List<String> ids) {
        try {
            return ApiResponse.success(this.removeByIds(ids));
        } catch (Exception e) {
            throw new HussarException("删除失败");
        }
    }

    @Override
    public ApiResponse<MesScadaTunnelkilnRecordPageVO> hussarQuery() {
        try {
            MesScadaTunnelkilnRecordPageVO mesScadaTunnelkilnRecordPageVO = new MesScadaTunnelkilnRecordPageVO();
            List<MesScadaTunnelkilnRecord> list = this.list();
            mesScadaTunnelkilnRecordPageVO.setData(list);
            if (HussarUtils.isNotEmpty(list)) {
                mesScadaTunnelkilnRecordPageVO.setCount((long) list.size());
            }
            mesScadaTunnelkilnRecordPageVO.setCode(RETURN_CODE);
            return ApiResponse.success(mesScadaTunnelkilnRecordPageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询失败");
        }
    }

    @Override
    public ApiResponse<MesScadaTunnelkilnRecord> formQuery(String id) {
        try {
            return ApiResponse.success(this.getById(id));
        } catch (Exception e) {
            throw new HussarException("表单查询失败");
        }
    }

    @Override
    public ApiResponse<MesScadaTunnelkilnRecordPageVO> hussarQuerymesScadaTunnelkilnRecordSort_1Page(Page<MesScadaTunnelkilnRecord> page) {
        try {
            Page<MesScadaTunnelkilnRecord> pager = new Page<>(page.getCurrent(), page.getSize());
            pager.addOrder(new OrderItem("SHIJIAN", false));
            MesScadaTunnelkilnRecordPageVO mesScadaTunnelkilnRecordPageVO = new MesScadaTunnelkilnRecordPageVO();
            List<MesScadaTunnelkilnRecord> list = this.page(pager).getRecords();
            mesScadaTunnelkilnRecordPageVO.setData(list);
            mesScadaTunnelkilnRecordPageVO.setCount(pager.getTotal());
            mesScadaTunnelkilnRecordPageVO.setCode(RETURN_CODE);
            return ApiResponse.success(mesScadaTunnelkilnRecordPageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询失败");
        }
    }

    @Override
    public ApiResponse<MesScadaTunnelkilnRecordPageVO> hussarQuerymesScadaTunnelkilnRecordSort_1() {
        try {
            MesScadaTunnelkilnRecordPageVO mesScadaTunnelkilnRecordPageVO = new MesScadaTunnelkilnRecordPageVO();
            List<MesScadaTunnelkilnRecord> list = this.list(new QueryWrapper<MesScadaTunnelkilnRecord>().orderByDesc("SHIJIAN"));
            mesScadaTunnelkilnRecordPageVO.setData(list);
            if (HussarUtils.isNotEmpty(list)) {
                mesScadaTunnelkilnRecordPageVO.setCount((long) list.size());
            }
            mesScadaTunnelkilnRecordPageVO.setCode(RETURN_CODE);
            return ApiResponse.success(mesScadaTunnelkilnRecordPageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询失败");
        }
    }

    @Override
    public ApiResponse<MesScadaTunnelkilnRecordPageVO> hussarQuerymesScadaTunnelkilnRecordCondition_1mesScadaTunnelkilnRecordSort_1Page(MesScadaTunnelkilnRecordMesscadatunnelkilnrecorddataset1 messcadatunnelkilnrecorddataset1) {
        try {
            MesScadaTunnelkilnRecordPageVO mesScadaTunnelkilnRecordPageVO = new MesScadaTunnelkilnRecordPageVO();
            Page<MesScadaTunnelkilnRecord> pager = new Page<>(messcadatunnelkilnrecorddataset1.getCurrent(), messcadatunnelkilnrecorddataset1.getSize());
            pager.addOrder(new OrderItem("SHIJIAN", false));
            List<MesScadaTunnelkilnRecord> list = mesScadaTunnelkilnRecordMapper.hussarQuerymesScadaTunnelkilnRecordCondition_1mesScadaTunnelkilnRecordSort_1Page(pager, messcadatunnelkilnrecorddataset1);
            mesScadaTunnelkilnRecordPageVO.setData(list);
            mesScadaTunnelkilnRecordPageVO.setCount(pager.getTotal());
            mesScadaTunnelkilnRecordPageVO.setCode(RETURN_CODE);
            return ApiResponse.success(mesScadaTunnelkilnRecordPageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询失败");
        }
    }

    @Override
    public ApiResponse<MesScadaTunnelkilnRecordPageVO> hussarQuerymesScadaTunnelkilnRecordCondition_1mesScadaTunnelkilnRecordSort_1(MesScadaTunnelkilnRecordMesscadatunnelkilnrecorddataset1 messcadatunnelkilnrecorddataset1) {
        try {
            MesScadaTunnelkilnRecordPageVO mesScadaTunnelkilnRecordPageVO = new MesScadaTunnelkilnRecordPageVO();
            List<MesScadaTunnelkilnRecord> list = mesScadaTunnelkilnRecordMapper.hussarQuerymesScadaTunnelkilnRecordCondition_1mesScadaTunnelkilnRecordSort_1(messcadatunnelkilnrecorddataset1, new QueryWrapper<MesScadaTunnelkilnRecord>().orderByDesc("SHIJIAN"));
            mesScadaTunnelkilnRecordPageVO.setData(list);
            if (HussarUtils.isNotEmpty(list)) {
                mesScadaTunnelkilnRecordPageVO.setCount((long) list.size());
            }
            mesScadaTunnelkilnRecordPageVO.setCode(RETURN_CODE);
            return ApiResponse.success(mesScadaTunnelkilnRecordPageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询失败");
        }
    }
}
